package com.yy.utils;

import com.yy.model.ResultMsg;
import io.jsonwebtoken.Claims;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;

import com.yy.ant.sys.entity.User;
/**
 * Session管理工具类
 * @author Lenovo
 *
 */
public class SessionUtil {

	//取出Session管理的对象
    public static User getUserToSession(String token) {
		ResultMsg result = JwtUtils.validateJWT(token);
		Claims claims= (Claims) result.getData();
		User user=new User();
		user.setId(Long.valueOf(claims.getId()));
		user.setSuccess(result.isSuccess());
		user.setMsg(result.getMsg());
		return user;
        //return (User) SecurityUtils.getSubject().getPrincipal();
    }
    
    //判断是否是管理员
    public static boolean getAdmin(String name) {
		if (StringUtils.equals(name, "admin")) {
			return  true;
		}
        return false;
    }
}
